﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class SYS_CaseCause_SolveDAL
    {
        private string DbName;
        public SYS_CaseCause_SolveDAL()
        {
            DbName = "JudgeDoc";
        }

        /// <summary>
        /// 获取化解相关数据
        /// </summary>
        /// <param name="CC_ID"></param>
        /// <returns></returns>
        public DataTable GetCaseCauseSolve(string CC_ID)
        {
            string sql = " select *from  SYS_CaseCause_Solve where CC_ID='" + CC_ID + "' ";
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql.ToString());
            var otB = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (otB.Rows.Count > 0)
            {
                return otB;
            }
            return new DataTable();
        }


        /// <summary>
        /// 删除化解相关数据
        /// </summary>
        public bool DeleteCaseCauseData(string CC_ID)
        {
            string sql = string.Format(@" delete from SYS_CaseCause_Solve where CC_ID='{0}' ", CC_ID);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql.ToString());
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 增加化解相关数据
        /// </summary>
        public bool AddCaseCauseSolve(SYS_CaseCause_Solve model)
        {
            string sql = string.Format(@" insert into SYS_CaseCause_Solve(CCS_ID,CC_ID,CCS_SolveProject,CCS_SolveAdvise,CCS_SolveExpectResult) values('{0}','{1}','{2}','{3}','{4}') ", model.CCS_ID, model.CC_ID, model.CCS_SolveProject, model.CCS_SolveAdvise,model.CCS_SolveExpectResult);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql.ToString());
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

    }
}
